var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    port: "3306",
    user: 'user001',
    password: '123456',
    database: 'python_emp'
});

connection.connect((err) => {
    if (!err) {
        console.log("mysql 数据库连接成功")
    }
});

let sqlfunction = (sql) => {
    return new Promise((resolve, reject) => {
        connection.query(sql, function (error, results, fields) {
            if (error) throw reject(error);
            // console.log('The solution is: ', results[0].solution);
            resolve(results)
        });
    })
}

module.exports = sqlfunction;